﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

using QuDao;
using FineUICore;
using Kalman;
using Kalman.Extensions;

namespace AdminUI.Pages.OrderManage
{
    /// <summary>
    /// 确认发货
    /// </summary>
    public partial class Order30ConfirmModel : BaseModel
    {
        public void OnGet(long id)
        {
            Current = OrderBO.Instance.GetItem<Order>(id);

            var tenant = TenantBO.Instance.GetItem(Current.TID);
            var ss = tenant.ExpressCompanyList.Split('|');
            var items = new List<NameValueDto>();
            foreach (var s in ss)
            {
                items.Add(new NameValueDto { Name = s, Value = s});
            }
            ViewBag.ExpressCompanyList = items;

            var userList = UserBO.Instance.GetListByRole(OnlineTID, 2);
            ViewBag.UserList = userList;
        }

        public Order Current { get; set; }

        public IActionResult OnPostBtnSubmit_Click(long shipperID, long orderID, string expressCompany, string expressNo)
        {
            try
            {
                OrderBO.Instance.ConfirmDelivery(shipperID, orderID, expressCompany, expressNo);
                LogAction(ActionType.确认, $"确认发货：{orderID}-{expressCompany}{expressNo}");

                FineUICore.PageContext.RegisterStartupScript(ActiveWindow.GetHideRefreshReference());
                //ActiveWindow.HidePostBack();
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
                if (!(ex is AppException && ex.InnerException == null))
                {
                    msg = ex.ToString();
                }

                Alert.Show(msg, "错误信息", MessageBoxIcon.Error);
            }

            return UIHelper.Result();
        }

    }
}